//
//  LoginViewController.m
//  tianjin
//
//  Created by 鞠超 on 16/8/12.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "LoginViewController.h"

#import "RegistViewController.h"
#import "ZhaohuimimaViewController.h"

@interface LoginViewController () <UIScrollViewDelegate, UITextFieldDelegate>

@property (nonatomic, strong) UIScrollView * scrollView;
//
@property (nonatomic, strong) UITextField * text_zhanghao;
@property (nonatomic, strong) UITextField * text_mima;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void)p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    _topView.backgroundColor = [UIColor blackColor];
    
    _lblTitle.text = @"登录";
    _lblTitle.textColor = [UIColor whiteColor];
    _lblTitle.font = [UIFont systemFontOfSize:19];
    
    UIImageView * image_return = [[UIImageView alloc] initWithFrame:CGRectMake(15, 32, 10, 20)];
    image_return.image = [UIImage imageNamed:@"zuofanhui@2x.png"];
    [_topView addSubview:image_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(10, 20, 35, 44);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//显示tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
    self.scrollView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.scrollView.contentSize = CGSizeMake(0, SCREEN_HEIGHT - 60);
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.delegate = self;
    [self.view addSubview:self.scrollView];
    
    
    //1
    UIView * view_1 = [[UIView alloc] initWithFrame:CGRectMake(0, 15, SCREEN_WIDTH, 50)];
    view_1.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:view_1];
    
    UIView * view_line1 = [[UIView alloc] initWithFrame:CGRectMake(0, 49, SCREEN_WIDTH, 1)];
    view_line1.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [view_1 addSubview:view_line1];
    
    UIImageView * image_1 = [[UIImageView alloc] init];
    image_1.frame = CGRectMake(10, 17.5, 15, 15);
    image_1.image = [UIImage imageNamed:@"login_zhanghao@2x.png"];
    [view_1 addSubview:image_1];
    
    self.text_zhanghao = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_1.frame) + 15, 15, SCREEN_WIDTH - CGRectGetMaxX(image_1.frame) - 25, 20)];
    self.text_zhanghao.placeholder = @"请输入手机号";
    self.text_zhanghao.font = [UIFont systemFontOfSize:16];
    self.text_zhanghao.clearButtonMode = UITextFieldViewModeAlways;
    self.text_zhanghao.delegate = self;
    self.text_zhanghao.returnKeyType = UIReturnKeyDone;
    [view_1 addSubview:self.text_zhanghao];
    
    //2
    UIView * view_2 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(view_1.frame), SCREEN_WIDTH, 50)];
    view_2.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:view_2];
    
    UIView * view_line2 = [[UIView alloc] initWithFrame:CGRectMake(0, 49, SCREEN_WIDTH, 1)];
    view_line2.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [view_2 addSubview:view_line2];
    
    UIImageView * image_2 = [[UIImageView alloc] init];
    image_2.frame = CGRectMake(10, 17.5, 15, 15);
    image_2.image = [UIImage imageNamed:@"login_mima@2x.png"];
    [view_2 addSubview:image_2];
    
    self.text_mima = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_2.frame) + 15, 15, SCREEN_WIDTH - CGRectGetMaxX(image_2.frame) - 25, 20)];
    self.text_mima.placeholder = @"请输入密码";
    self.text_mima.font = [UIFont systemFontOfSize:16];
    self.text_mima.clearButtonMode = UITextFieldViewModeAlways;
    self.text_mima.delegate = self;
    self.text_mima.returnKeyType = UIReturnKeyDone;
    self.text_mima.secureTextEntry = YES;
    [view_2 addSubview:self.text_mima];
    
    //登录
    UIButton * btn_denglu = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_denglu.frame = CGRectMake(15, CGRectGetMaxY(view_2.frame) + 20, SCREEN_WIDTH - 30, 45);
    btn_denglu.backgroundColor = navi_bar_bg_color;
    btn_denglu.layer.cornerRadius = 5;
    btn_denglu.titleLabel.font = [UIFont systemFontOfSize:17];
    [btn_denglu setTitle:@"登录" forState:(UIControlStateNormal)];
    [btn_denglu setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [self.scrollView addSubview:btn_denglu];
    
    [btn_denglu addTarget:self action:@selector(btn_dengluAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //
    UILabel * lbl_1 = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(btn_denglu.frame) + 15, 100, 15)];
    lbl_1.text = @"去注册";
    lbl_1.textColor = navi_bar_bg_color;
    lbl_1.font = [UIFont systemFontOfSize:14];
    [self.scrollView addSubview:lbl_1];
    
    UIButton * btn_quzhuce = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_quzhuce.frame = CGRectMake(15, CGRectGetMaxY(btn_denglu.frame) + 10, 80, 30);
    [self.scrollView addSubview:btn_quzhuce];
    [btn_quzhuce addTarget:self action:@selector(btn_quzhuceAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //
    UILabel * lbl_2 = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 15 - 100, CGRectGetMaxY(btn_denglu.frame) + 15, 100, 15)];
    lbl_2.text = @"找回密码";
    lbl_2.textAlignment = NSTextAlignmentRight;
    lbl_2.textColor = navi_bar_bg_color;
    lbl_2.font = [UIFont systemFontOfSize:14];
    [self.scrollView addSubview:lbl_2];
    
    UIButton * btn_zhaohui = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_zhaohui.frame = CGRectMake(SCREEN_WIDTH - 90, CGRectGetMaxY(btn_denglu.frame) + 10, 80, 30);
    [self.scrollView addSubview:btn_zhaohui];
    [btn_zhaohui addTarget:self action:@selector(btn_zhaohuiAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    //
    UILabel * lbl_disanfang = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 - 40, SCREEN_HEIGHT - 64 - 120, 80, 15)];
    lbl_disanfang.text = @"第三方登录";
    lbl_disanfang.font = [UIFont systemFontOfSize:14];
    lbl_disanfang.textAlignment = NSTextAlignmentCenter;
    lbl_disanfang.textColor = [UIColor grayColor];
    [self.scrollView addSubview:lbl_disanfang];
    
    UIView * view_L = [[UIView alloc] initWithFrame:CGRectMake(30, CGRectGetMidY(lbl_disanfang.frame), SCREEN_WIDTH / 2 - 40 - 30, 0.5)];
    view_L.backgroundColor = [UIColor grayColor];
    [self.scrollView addSubview:view_L];
    
    UIView * view_R = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(lbl_disanfang.frame), CGRectGetMidY(lbl_disanfang.frame), SCREEN_WIDTH / 2 - 40 - 30, 0.5)];
    view_R.backgroundColor = [UIColor grayColor];
    [self.scrollView addSubview:view_R];
    
    //
    UIImageView * image_xia = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 - 5, CGRectGetMaxY(lbl_disanfang.frame) + 10, 10, 6)];
    image_xia.image = [UIImage imageNamed:@"xiafanhui@2x.png"];
    [self.scrollView addSubview:image_xia];
    
    CGFloat length_x = (SCREEN_WIDTH - 40 * 5) / 2;
    //
    UIButton * btn_weixin = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_weixin.frame = CGRectMake(length_x, CGRectGetMaxY(image_xia.frame) + 15, 40, 40);
    [btn_weixin setBackgroundImage:[UIImage imageNamed:@"login_weixin@2x.png"] forState:(UIControlStateNormal)];
    [self.scrollView addSubview:btn_weixin];
    [btn_weixin addTarget:self action:@selector(btn_weixinAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //
    UIButton * btn_QQ = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_QQ.frame = CGRectMake(CGRectGetMaxX(btn_weixin.frame) + 40, CGRectGetMaxY(image_xia.frame) + 15, 40, 40);
    [btn_QQ setBackgroundImage:[UIImage imageNamed:@"login_qq@2x.png"] forState:(UIControlStateNormal)];
    [self.scrollView addSubview:btn_QQ];
    [btn_QQ addTarget:self action:@selector(btn_QQAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //
    UIButton * btn_sina = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_sina.frame = CGRectMake(CGRectGetMaxX(btn_QQ.frame) + 40, CGRectGetMaxY(image_xia.frame) + 15, 40, 40);
    [btn_sina setBackgroundImage:[UIImage imageNamed:@"login_weibo@2x.png"] forState:(UIControlStateNormal)];
    [self.scrollView addSubview:btn_sina];
    [btn_sina addTarget:self action:@selector(btn_sinaAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

#pragma mark - 点击登录
- (void )btn_dengluAction:(UIButton *)sender
{
    NSLog(@"点击登录");
}

#pragma mark - 去注册
- (void )btn_quzhuceAction:(UIButton *)sender
{
//    NSLog(@"去注册");
    
    RegistViewController * registViewController = [[RegistViewController alloc] init];
    [self showViewController:registViewController sender:nil];
}

#pragma mark - 找回密码
- (void )btn_zhaohuiAction:(UIButton *)sender
{
//    NSLog(@"找回密码");
    
    ZhaohuimimaViewController * zhaohuimimaViewController = [[ZhaohuimimaViewController alloc] init];
    [self showViewController:zhaohuimimaViewController sender:nil];
}

#pragma mark - 微信登录
- (void )btn_weixinAction:(UIButton *)sender
{
    NSLog(@"微信登录");
}

#pragma mark - QQ登录
- (void )btn_QQAction:(UIButton *)sender
{
    NSLog(@"QQ登录");
}

#pragma mark - 微博登录
- (void )btn_sinaAction:(UIButton *)sender
{
    NSLog(@"微博登录");
}

#pragma mark - textfiled代理
- (BOOL )textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    
    [UIView animateWithDuration:0.7 animations:^{
        
        self.scrollView.contentOffset = CGPointMake(0, 0);
        
    } completion:^(BOOL finished) {
        
    }];
    
    return YES;
}

#pragma mark - scrollView代理
- (void )scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [self.text_zhanghao resignFirstResponder];
    [self.text_mima resignFirstResponder];
}









@end
